package com.youlu.campus.admin.feedback.controller;

import com.youlu.campus.admin.feedback.dto.FeedBackQueryRequest;
import com.youlu.campus.admin.feedback.dto.FeedBackQueryResponse;
import com.youlu.campus.admin.feedback.dto.FeedBackUpdateRequest;
import com.youlu.campus.admin.feedback.entity.FeedBackInfo;
import com.youlu.campus.admin.feedback.service.FeedBackInfoService;
import com.youlu.campus.admin.utils.AuthUtils;
import com.yuelin.infrastructure.quantum.common.QResult;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import javax.validation.constraints.NotNull;

/**
 * 问题反馈
 *
 */
@RestController
public class FeedBackController {
    @Autowired
    private FeedBackInfoService feedBackInfoService;
    /**
     * 问题反馈
     * 备注：问题反馈
     * @param request 问题反馈请求类
     * @return 请求成功时返回FeedBackQueryResponse对象
     */
    @PostMapping("/feed-back/list")
    public QResult listPages(@RequestBody @Valid @NotNull FeedBackQueryRequest request) {
        request.setTenantId(AuthUtils.getComId());
        return QResult.success(feedBackInfoService.list(request));
    }

    /**
     * 处理问题反馈
     * 备注：处理问题反馈
     * @param request 问题反馈修改类
     * @return 请求成功时返回Boolean对象
     */
    @PostMapping("/feed-back/update")
    public QResult update(@RequestBody @Valid @NotNull FeedBackUpdateRequest request) {
        FeedBackInfo feedBackInfo = new FeedBackInfo();
        BeanUtils.copyProperties(request, feedBackInfo);
        feedBackInfo.setTenantId(AuthUtils.getComId());
        return QResult.success(feedBackInfoService.updateFeedBackInfo(feedBackInfo));
    }

    @GetMapping("/feed-back/delete")
    public QResult delete(@RequestParam("id") String id) {
        return QResult.success(feedBackInfoService.delete(id));
    }
}
